var numberFormate = iot.getNumberFormat("0");
dev.action = function(resp,param){
    var devId = param.id;
    var theTime = param.time;
    var workSpace = param.workSpace;
    var jsData =  iot.list();
    var db = iot.db();
    var result = db.qry("select *,SUM(dev_win.dvalue) totalSum,dev.name as devName from\n" +
        "iot_dev_data_win dev_win\n" +
        "LEFT JOIN iot_dev dev\n" +
        "on dev_win.dev_id = dev.id,\n" +
        "(select * from energy_struc_prop where type = 1 and energy_struc_id in (select id from energy_struc where name = (select name from energy_struc where id = "+ workSpace +"))) esp\n" +
        "where 1=1\n" +
        "and dev_win.dev_id = esp.dev_id\n" +
        "and dev_win.data_type = esp.name\n" +
        "and DATE_FORMAT(dev_win.the_time,'%Y-%m-%d %H:%i:%s') like '"+ theTime +"%'\n" +
        "GROUP BY esp.dev_id");

    var resultYield = db.qry("select *,SUM(dev_win.dvalue) totalSum from\n" +
        "iot_dev_data_win dev_win\n" +
        "where 1=1\n" +
        "and dev_win.data_type = '_产量'\n" +
        "and DATE_FORMAT(dev_win.the_time,'%Y-%m-%d %H:%i:%s') like '"+ theTime +"%'");
    var vl = result.getValue();
    var vlYield = resultYield.getValue();
    result.forAll(function(item,ix,cnt){
        if (item.devName == "工厂压缩空气表"){
            jsData.add({planNum: numberFormate.format(item.totalSum), unit: item.unit, type: "总空气", useNum: numberFormate.format(item.totalSum), percent: "0%"});
            jsData.add({planNum: vlYield['0'].totalSum, unit: item.unit+"/辆", type: "单车空气", useNum: numberFormate.format(item.totalSum/vlYield['0'].totalSum), percent: "0%"});
        }
        if (item.devName == "工厂冷量表"){
            jsData.add({planNum: numberFormate.format(item.totalSum), unit: item.unit, type: "总冷量", useNum: numberFormate.format(item.totalSum), percent: "0%"});
            jsData.add({planNum: vlYield['0'].totalSum, unit: item.unit+"/辆", type: "单车冷量", useNum: numberFormate.format(item.totalSum/vlYield['0'].totalSum), percent: "0%"});
        }
        if (item.devName == "工厂碳排表"){
            jsData.add({planNum: numberFormate.format(item.totalSum), unit: item.unit, type: "总碳排", useNum: numberFormate.format(item.totalSum), percent: "0%"});
            jsData.add({planNum: vlYield['0'].totalSum, unit: item.unit+"/辆", type: "单车碳排", useNum: numberFormate.format(item.totalSum/vlYield['0'].totalSum), percent: "0%"});
        }
        if (item.devName == "工厂成本表"){
            jsData.add({planNum: numberFormate.format(item.totalSum), unit: item.unit, type: "总成本", useNum: numberFormate.format(item.totalSum), percent: "0%"});
            jsData.add({planNum: vlYield['0'].totalSum, unit: item.unit+"/辆", type: "单车成本", useNum: numberFormate.format(item.totalSum/vlYield['0'].totalSum), percent: "0%"});
        }
        if (item.devName == "工厂燃气表"){
            jsData.add({planNum: numberFormate.format(item.totalSum), unit: item.unit, type: "总燃气", useNum: numberFormate.format(item.totalSum), percent: "0%"});
            jsData.add({planNum: vlYield['0'].totalSum, unit: item.unit+"/辆", type: "单车燃气", useNum: numberFormate.format(item.totalSum/vlYield['0'].totalSum), percent: "0%"});
        }
    });

    resp.setJsData(jsData);
}